package com.zjlanyun.eplus.view.report.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gigamole.navigationtabstrip.NavigationTabStrip;
import com.zjlanyun.eplus.R;
import com.zjlanyun.eplus.view.report.MyViewPage;
import com.zjlanyun.eplus.view.report.adapter.MyPagerAdapter;

import static com.zjlanyun.eplus.view.report.UtilConstants.DEFAULT_CHECK;
import static com.zjlanyun.eplus.view.report.UtilConstants.MODEL_ID;
import static com.zjlanyun.eplus.view.report.UtilConstants.SQL_CONDITION;
import static com.zjlanyun.eplus.view.report.UtilConstants.TITLE1;
import static com.zjlanyun.eplus.view.report.UtilConstants.TITLE2;

/**
 * 作者：韩笑 on 2017/6/26 0026 08:19
 * <p>
 * 作用：饼状统计图主页面（包含子页面：饼状统计图以及统计表格）
 */


public class PeiMainFragment extends Fragment {
    private static final String TAG = "PeiMainFragment";
    private NavigationTabStrip navigationTabStrip;//顶部导航栏
    private MyViewPage mViewPager;
    private String modelId = null;//模型id
    private String sql = null;//条件

    public static PeiMainFragment newInstance(String modelId,String sql) {
        Bundle args = new Bundle();
        PeiMainFragment fragment = new PeiMainFragment();
        args.putString(MODEL_ID, modelId);
        args.putString(SQL_CONDITION, sql);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.pei_main_fragment, null);
        Log.d(TAG,getArguments().getString(MODEL_ID)+"///"+getArguments().getString(SQL_CONDITION));
        initView(view);
        return view;
    }

    /**
     * ViewPager
     * @param mViewPager
     */
    public void setupViewPager(ViewPager mViewPager){
        MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
        adapter.addFragment(PieFragment.newInstance(modelId,sql), "饼状统计图");
       // adapter.addFragment(TableFragment.newInstance(modelId,sql),"表格");
        mViewPager.setAdapter(adapter);
    }

    /**
     * 初始化
     * @param view
     */
    public void initView(View view){
        modelId = getArguments().getString(MODEL_ID);
        sql = getArguments().getString(SQL_CONDITION);
        if (navigationTabStrip == null)
            navigationTabStrip = (NavigationTabStrip)view.findViewById(R.id.navigationTabStrip);
        mViewPager = (MyViewPage)view.findViewById(R.id.viewpager);
        setupViewPager(mViewPager);
        navigationTabStrip.setTitles(TITLE1,TITLE2);
        navigationTabStrip.setViewPager(mViewPager,DEFAULT_CHECK);
        navigationTabStrip.setStripType(NavigationTabStrip.StripType.LINE);
        navigationTabStrip.setVisibility(View.GONE);
    }

}
